package com.mesSystem.controller;

import com.mesSystem.dto.Result;
import com.mesSystem.entity.Process;
import com.mesSystem.service.impl.ProcessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@ResponseBody
@RequestMapping("process")
public class ProcessController {
    @Autowired
    ProcessService processService;


    @PostMapping("increase")
    public Result increase(@RequestBody Process process) {
        try {
            processService.save(process);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("工序似乎已存在");
        }

        return Result.ok("创建成功");
    }

    /**
     * 更新操作（名字暂不可更新）
     * @param process
     * @return
     */
    @PostMapping("update")
    public Result update(@RequestBody Process process) {
        try {
            log.info(process.toString());
            processService.updateById(process);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("工序名不可更新（其他错误请联系管理员）");
        }
        return Result.ok("更新成功");
    }

    @DeleteMapping("delete")
    public Result delete(Long processId) {
        processService.removeById(processId);
        return Result.ok("删除成功");
    }


}
